package tech.aistar.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.Phone;
import tech.aistar.mapper.PhoneMapper;
import tech.aistar.service.IPhoneService;
import java.util.List;
/**
 * Created by 张庆昇 on 2020/1/1.
 */
@Service
public class PhoneServiceImpl implements IPhoneService{
    @Autowired
    private PhoneMapper phoneMapper;

    @Override
    public List<Phone> findAll() {
        return phoneMapper.findAll();
    }


    @Override
    public List<Phone> getAll(String phoneName) {
        //String s1 = "";
        //String s2 = null;

        //当敲入很多空格或者bookName根本就没有传入值(null)
        if(null == phoneName || phoneName.trim().length() == 0){
            //return语句当使用方式 - 用来结束方法当执行
            return phoneMapper.findAll();
        }

        //trim() - 用来去除字符串左右当空格
        //"           ".trim() -> 长度为0当字符串 - 空字符串->""
        return phoneMapper.findByPhoneName(phoneName.trim());
    }

    @Override
    public void deleteById(Integer id) {
        phoneMapper.deleteById(id);
    }

    @Override
    public Phone getById(Integer id) {
        return phoneMapper.getById(id);
    }

    @Override
    public void update(Phone b) {
        phoneMapper.update(b);
    }
}
